include($$PWD/../../global_variable.pri)

TARGET = sqlitecipher

android {
    TEMPLATE = app
} else {
    TEMPLATE = lib
}

QT_FOR_CONFIG += sqldrivers-private

CONFIG  += c++11 plugin

include($$PWD/sqlite3/sqlite3.pri)

target.path = $$[QT_INSTALL_PLUGINS]/sqldrivers/
INSTALLS += target

HEADERS  += \
    $$PWD/sqlitecipher_p.h \
    $$PWD/sqlitecipher_global.h
SOURCES  += \
    $$PWD/smain.cpp \
    $$PWD/sqlitecipher.cpp
OTHER_FILES += SqliteCipherDriverPlugin.json

!system-sqlite:!contains( LIBS, .*sqlite.* ) {
    CONFIG(release, debug|release):DEFINES *= NDEBUG
    DEFINES += SQLITE_OMIT_LOAD_EXTENSION SQLITE_OMIT_COMPLETE SQLITE_ENABLE_FTS3 SQLITE_ENABLE_FTS3_PARENTHESIS SQLITE_ENABLE_RTREE SQLITE_USER_AUTHENTICATION
    !contains(CONFIG, largefile):DEFINES += SQLITE_DISABLE_LFS
    winrt: DEFINES += SQLITE_OS_WINRT
    winphone: DEFINES += SQLITE_WIN32_FILEMAPPING_API=1
    qnx: DEFINES += _QNX_SOURCE
} else {
    LIBS += $$QT_LFLAGS_SQLITE
    QMAKE_CXXFLAGS *= $$QT_CFLAGS_SQLITE
}

QT = core core-private sql-private

PLUGIN_CLASS_NAME = SqliteCipherDriverPlugin

PLUGIN_TYPE = sqldrivers
load(qt_plugin)

DEFINES += QT_NO_CAST_TO_ASCII QT_NO_CAST_FROM_ASCII

QMAKE_CFLAGS += -march=native

contains(COMPILATION_METHOD, yxz) {
    # 编译输出
    TARGET_DIR = $$PWD/../../third_libs/sqlitecipher
    DESTDIR = $$TARGET_DIR/$$ARCH_PATH/$$QT_VERSION_PATH/$$BUILD_TYPE
    # 构造完成后，复制头文件到指定目录的命令，适用于Unix和Windows系统
    win32 {
        # Windows系统下的命令，复制头文件到third_libs内，dll复制到QT安装目录内
        QMAKE_POST_LINK += xcopy \"$$replace(PWD, /, \\)\\*.h\" \"$$replace(TARGET_DIR, /, \\)\\include\\\" /s /h /o /k /y && \
                            xcopy \"$$replace(DESTDIR, /, \\)\\*.dll\" \"$$replace(target.path, /, \\)\\\" /s /h /o /k /y && \
                            xcopy \"$$replace(DESTDIR, /, \\)\\*.lib\" \"$$replace(target.path, /, \\)\\\" /s /h /o /k /y
    } else {
        # Unix系统（包括Linux和macOS）下的命令
        QMAKE_POST_LINK += mkdir -p $$TARGET_DIR/include && find $$PWD -type f -name "*.h" -exec cp {} $$TARGET_DIR \;
    }
    message($$target.path)
}

